package com.yupi.yurpc.proxy;

import com.yupi.yurpc.RpcApplication;

import java.lang.reflect.Proxy;

/*
服务代理工厂(用于创建代理对象)
 */
public class SeriviceProxyFactory {

    /**
     * 根据服务类获取代理对象
     * @param interfaceClass
     * @return
     * @param <T>
     */
    public static <T> T getProxy(Class<T> interfaceClass){


        return (T) Proxy.newProxyInstance(interfaceClass.getClassLoader(),
                new Class[]{interfaceClass},
                new ServiceProxy());
    }

    /**
     *
     根据服务类获取 Mock 代理对象
     *
     * @param serviceClass
     * @param <T>
     * @return
     */
    public static <T> T getMockProxy(Class<T> serviceClass) {
        return (T) Proxy.newProxyInstance(
                serviceClass.getClassLoader(),
                new Class[]{serviceClass},
                new MockServiceProxy());
    }
}
